#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>


struct Node {
    __int128 p;
    __int128 q;
};

__int128 Gcd(const __int128 a, const __int128 b) {
    return b ? Gcd(b, a % b) : a;
}

Node Divide(const __int128 p, const __int128 q) {
    if (p == 0) return Node{ 0, 1 };
    const __int128 g = Gcd(p, q);
    return Node{ p / g, q / g };
}

__int128 Lcm(const __int128 a, const __int128 b) {
    return a / Gcd(a, b) * b;
}

Node Add(const Node& a, const Node& b) {
    if (a.q == 0) return b;
    if (b.q == 0) return a;
    const __int128 q = Lcm(a.q, b.q);
    const __int128 p = a.p * (q / a.q) + b.p * (q / b.q);
    return Divide(p, q);
}

Node MultiplyQ(const Node& a, const int b) {
    return Divide(a.p, a.q * b);
}

// 输出 __int128 类型的函数
void Print128(__int128 x) {
    if (x == 0) {
        std::cout << 0;
        return;
    }
    if (x < 0) {
        std::cout << '-';
        x = -x;
    }
    std::string s;
    while (x) {
        s += '0' + x % 10;
        x /= 10;
    }
    std::reverse(s.begin(), s.end());
    std::cout << s;
}

/**
 * NOIP2020 排水系统
 * 
 * https://www.luogu.com.cn/problem/P7113
 */
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);	

    int n, m;
    std::cin >> n >> m;

    std::vector<std::vector<int>> graph(n + 1);
    std::vector<Node> nodes(n + 1, { 0, 1 });
    std::vector<int> indegree(n + 1), outdegree(n + 1);

    for (int i = 1; i <= n; ++i) {
        int d;
        std::cin >> d;
        outdegree[i] = d;
        for (int j = 0; j < d; ++j) {
            int to;
            std::cin >> to;
            graph[i].push_back(to);
            indegree[to]++;
        }
    }

    std::queue<int> q;
    for (int i = 1; i <= m; ++i) {
        q.push(i);
        nodes[i] = { 1, 1 };
    }

    while (!q.empty()) {
        const int u = q.front();
    	q.pop();

        if (outdegree[u] > 0) {
            Node part = MultiplyQ(nodes[u], outdegree[u]);
            for (int v : graph[u]) {
                nodes[v] = Add(nodes[v], part);
                if (--indegree[v] == 0) {
                    q.push(v);
                }
            }
        }
    }

    for (int i = 1; i <= n; ++i) {
        if (outdegree[i] == 0) {
            const Node res = Divide(nodes[i].p, nodes[i].q);
            Print128(res.p);
            std::cout << " ";
            Print128(res.q);
            std::cout << "\n";
        }
    }

    return 0;
}